package com.lm.itextpdf.example;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.canvas.parser.PdfTextExtractor;

public class ExtractTextExample {
    public static void main(String[] args) throws Exception {
        String src = "input.pdf";
        PdfDocument pdfDoc = new PdfDocument(new PdfReader(src));

        for (int i = 1; i <= pdfDoc.getNumberOfPages(); i++) {
            String text = PdfTextExtractor.getTextFromPage(pdfDoc.getPage(i));
            System.out.println("Page " + i + ": " + text);
        }

        pdfDoc.close();
    }
}
